package com.lx.order.controller;


import com.lx.order.entities.UserOrder;
import com.lx.order.mapper.OrderMapper;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dh
 * @since 2024-10-23
 */
@RestController
@RequestMapping("/order")
public class OrderController2 {
    @Resource
    RocketMQTemplate rocketMqTemplate;

    @PostMapping("/orderAndPoints")
    public String orderAndPoints(@RequestBody  UserOrder order){
        TransactionSendResult transactionSendResult = rocketMqTemplate.sendMessageInTransaction(
                "transaction-topic",
                MessageBuilder.withPayload(order).build(),
                null);
        //消息发送状态
//        SendStatus sendStatus = transactionSendResult.getSendStatus();
//        //本地事务状态
//        String localState = transactionSendResult.getLocalTransactionState().name();
//
//        System.out.println("发送状态:{},本地事务执行状态:{}"+ sendStatus+ "    " + localState);
        return order.toString();
    }
}
